<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE html 
     PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
     "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
  <title>Module: Origami::Filter::Predictor</title>
  <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
  <meta http-equiv="Content-Script-Type" content="text/javascript" />
  <link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
  <script type="text/javascript">
  // <![CDATA[

  function popupCode( url ) {
    window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
  }

  function toggleCode( id ) {
    if ( document.getElementById )
      elem = document.getElementById( id );
    else if ( document.all )
      elem = eval( "document.all." + id );
    else
      return false;

    elemStyle = elem.style;
    
    if ( elemStyle.display != "block" ) {
      elemStyle.display = "block"
    } else {
      elemStyle.display = "none"
    }

    return true;
  }
  
  // Make codeblocks hidden by default
  document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
  
  // ]]>
  </script>

</head>
<body>



    <div id="classHeader">
        <table class="header-table">
        <tr class="top-aligned-row">
          <td><strong>Module</strong></td>
          <td class="class-name-in-header">Origami::Filter::Predictor</td>
        </tr>
        <tr class="top-aligned-row">
            <td><strong>In:</strong></td>
            <td>
                <a href="../../../files/origami/filters/predictors_rb.html">
                origami/filters/predictors.rb
                </a>
        <br />
            </td>
        </tr>

        </table>
    </div>
  <!-- banner header -->

  <div id="bodyContent">



  <div id="contextContent">



   </div>

    <div id="method-list">
      <h3 class="section-bar">Methods</h3>

      <div class="name-list">
      <a href="#M000346">do_png_post_prediction</a>&nbsp;&nbsp;
      <a href="#M000347">do_png_pre_prediction</a>&nbsp;&nbsp;
      <a href="#M000345">do_post_prediction</a>&nbsp;&nbsp;
      <a href="#M000344">do_pre_prediction</a>&nbsp;&nbsp;
      </div>
    </div>

  </div>


    <!-- if includes -->

    <div id="section">


    <div id="constants-list">
      <h3 class="section-bar">Constants</h3>

      <div class="name-list">
        <table summary="Constants">
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">NONE</td>
          <td>=</td>
          <td class="context-item-value">1</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">TIFF</td>
          <td>=</td>
          <td class="context-item-value">2</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">PNG_NONE</td>
          <td>=</td>
          <td class="context-item-value">10</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">PNG_SUB</td>
          <td>=</td>
          <td class="context-item-value">11</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">PNG_UP</td>
          <td>=</td>
          <td class="context-item-value">12</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">PNG_AVERAGE</td>
          <td>=</td>
          <td class="context-item-value">13</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">PNG_PAETH</td>
          <td>=</td>
          <td class="context-item-value">14</td>
        </tr>
        <tr class="top-aligned-row context-row">
          <td class="context-item-name">PNG_OPTIMUM</td>
          <td>=</td>
          <td class="context-item-value">15</td>
        </tr>
        </table>
      </div>
    </div>



      


    <!-- if method_list -->
    <div id="methods">
      <h3 class="section-bar">Public Class methods</h3>

      <div id="method-M000346" class="method-detail">
        <a name="M000346"></a>

        <div class="method-heading">
          <a href="#M000346" class="method-signature">
          <span class="method-name">do_png_post_prediction</span><span class="method-args">(data, bpp, bpr)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000346-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000346-source">
<pre>
     <span class="ruby-comment cmt"># File origami/filters/predictors.rb, line 108</span>
108:       <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">do_png_post_prediction</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">bpp</span>, <span class="ruby-identifier">bpr</span>)
109: 
110:         <span class="ruby-identifier">result</span> = <span class="ruby-value str">&quot;&quot;</span>
111:         <span class="ruby-identifier">uprow</span> = <span class="ruby-value str">&quot;\0&quot;</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">bpr</span>
112:         <span class="ruby-identifier">thisrow</span> = <span class="ruby-value str">&quot;\0&quot;</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">bpr</span>
113:         <span class="ruby-identifier">nrows</span> = (<span class="ruby-identifier">data</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">bpr</span> <span class="ruby-operator">-</span> <span class="ruby-value">1</span>) <span class="ruby-operator">/</span> <span class="ruby-identifier">bpr</span>
114:         
115:         <span class="ruby-identifier">nrows</span>.<span class="ruby-identifier">times</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">irow</span><span class="ruby-operator">|</span>
116: 
117:           <span class="ruby-identifier">line</span> = <span class="ruby-identifier">data</span>[<span class="ruby-identifier">irow</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">bpr</span>, <span class="ruby-identifier">bpr</span>]
118:           <span class="ruby-identifier">predictor</span> = <span class="ruby-value">10</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">line</span>[<span class="ruby-value">0</span>].<span class="ruby-identifier">ord</span>
119:           <span class="ruby-identifier">line</span>[<span class="ruby-value">0</span>] = <span class="ruby-value str">&quot;\0&quot;</span>
120: 
121:           <span class="ruby-keyword kw">for</span> <span class="ruby-identifier">i</span> <span class="ruby-keyword kw">in</span> (<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-identifier">line</span>.<span class="ruby-identifier">size</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>)
122:             <span class="ruby-identifier">up</span> = <span class="ruby-identifier">uprow</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">ord</span>
123: 
124:             <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">bpp</span> <span class="ruby-operator">&gt;</span> <span class="ruby-identifier">i</span>
125:               <span class="ruby-identifier">left</span> = <span class="ruby-identifier">upleft</span> = <span class="ruby-value">0</span>
126:             <span class="ruby-keyword kw">else</span>
127:               <span class="ruby-identifier">left</span> = <span class="ruby-identifier">line</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">-</span><span class="ruby-identifier">bpp</span>].<span class="ruby-identifier">ord</span>
128:               <span class="ruby-identifier">upleft</span> = <span class="ruby-identifier">uprow</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">-</span><span class="ruby-identifier">bpp</span>].<span class="ruby-identifier">ord</span>
129:             <span class="ruby-keyword kw">end</span>
130: 
131:             <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">predictor</span>
132:               <span class="ruby-keyword kw">when</span> <span class="ruby-constant">PNG_NONE</span>
133:                 <span class="ruby-identifier">thisrow</span> = <span class="ruby-identifier">line</span> 
134:               <span class="ruby-keyword kw">when</span> <span class="ruby-constant">PNG_SUB</span>
135:                 <span class="ruby-identifier">thisrow</span>[<span class="ruby-identifier">i</span>] = ((<span class="ruby-identifier">line</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">left</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0x</span><span class="ruby-constant">FF</span>).<span class="ruby-identifier">chr</span>
136:               <span class="ruby-keyword kw">when</span> <span class="ruby-constant">PNG_UP</span>
137:                 <span class="ruby-identifier">thisrow</span>[<span class="ruby-identifier">i</span>] = ((<span class="ruby-identifier">line</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">up</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0x</span><span class="ruby-constant">FF</span>).<span class="ruby-identifier">chr</span>
138:               <span class="ruby-keyword kw">when</span> <span class="ruby-constant">PNG_AVERAGE</span>
139:                 <span class="ruby-identifier">thisrow</span>[<span class="ruby-identifier">i</span>] = ((<span class="ruby-identifier">line</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">+</span> ((<span class="ruby-identifier">left</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">up</span>) <span class="ruby-operator">/</span> <span class="ruby-value">2</span>)) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0x</span><span class="ruby-constant">FF</span>).<span class="ruby-identifier">chr</span>
140:               <span class="ruby-keyword kw">when</span> <span class="ruby-constant">PNG_PAETH</span>
141:                 <span class="ruby-identifier">p</span> = <span class="ruby-identifier">left</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">up</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">upleft</span>
142:                 <span class="ruby-identifier">pa</span>, <span class="ruby-identifier">pb</span>, <span class="ruby-identifier">pc</span> = (<span class="ruby-identifier">p</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">left</span>).<span class="ruby-identifier">abs</span>, (<span class="ruby-identifier">p</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">up</span>).<span class="ruby-identifier">abs</span>, (<span class="ruby-identifier">p</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">upleft</span>).<span class="ruby-identifier">abs</span>
143: 
144:                 <span class="ruby-identifier">thisrow</span>[<span class="ruby-identifier">i</span>] = ((<span class="ruby-identifier">line</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">+</span> 
145:                   <span class="ruby-keyword kw">case</span> [ <span class="ruby-identifier">pa</span>, <span class="ruby-identifier">pb</span>, <span class="ruby-identifier">pc</span> ].<span class="ruby-identifier">min</span>
146:                     <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">pa</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">left</span>
147:                     <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">pb</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">up</span>
148:                     <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">pc</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">upleft</span>
149:                   <span class="ruby-keyword kw">end</span>
150:                 ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0x</span><span class="ruby-constant">FF</span>).<span class="ruby-identifier">chr</span>
151:             <span class="ruby-keyword kw">else</span>
152:               <span class="ruby-identifier">puts</span> <span class="ruby-node">&quot;Unknown PNG predictor : #{predictor}&quot;</span>
153:               <span class="ruby-identifier">thisrow</span> = <span class="ruby-identifier">line</span>
154:             <span class="ruby-keyword kw">end</span>
155:             
156:           <span class="ruby-keyword kw">end</span>
157: 
158:           <span class="ruby-identifier">result</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">thisrow</span>[<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">-1</span>]
159:           <span class="ruby-identifier">uprow</span> = <span class="ruby-identifier">thisrow</span>
160:         <span class="ruby-keyword kw">end</span>
161:   
162:         <span class="ruby-identifier">result</span>
163:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000347" class="method-detail">
        <a name="M000347"></a>

        <div class="method-heading">
          <a href="#M000347" class="method-signature">
          <span class="method-name">do_png_pre_prediction</span><span class="method-args">(data, predictor, bpp, bpr)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000347-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000347-source">
<pre>
     <span class="ruby-comment cmt"># File origami/filters/predictors.rb, line 165</span>
165:       <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">do_png_pre_prediction</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">predictor</span>, <span class="ruby-identifier">bpp</span>, <span class="ruby-identifier">bpr</span>)
166:         
167:         <span class="ruby-identifier">result</span> = <span class="ruby-value str">&quot;&quot;</span>
168:         <span class="ruby-identifier">nrows</span> = <span class="ruby-identifier">data</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">/</span> <span class="ruby-identifier">bpr</span>
169: 
170:         <span class="ruby-identifier">line</span> = <span class="ruby-value str">&quot;\0&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">data</span>[<span class="ruby-operator">-</span><span class="ruby-identifier">bpr</span>, <span class="ruby-identifier">bpr</span>]
171:         
172:         (<span class="ruby-identifier">nrows</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>).<span class="ruby-identifier">downto</span>(<span class="ruby-value">0</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">irow</span><span class="ruby-operator">|</span>
173: 
174:           <span class="ruby-identifier">uprow</span> = 
175:           <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">irow</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span> 
176:             <span class="ruby-value str">&quot;\0&quot;</span> <span class="ruby-operator">*</span> (<span class="ruby-identifier">bpr</span><span class="ruby-operator">+</span><span class="ruby-value">1</span>) 
177:           <span class="ruby-keyword kw">else</span> 
178:             <span class="ruby-value str">&quot;\0&quot;</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">data</span>[(<span class="ruby-identifier">irow</span><span class="ruby-operator">-</span><span class="ruby-value">1</span>)<span class="ruby-operator">*</span><span class="ruby-identifier">bpr</span>,<span class="ruby-identifier">bpr</span>]
179:           <span class="ruby-keyword kw">end</span>
180: 
181:           <span class="ruby-identifier">bpr</span>.<span class="ruby-identifier">downto</span>(<span class="ruby-value">1</span>) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">i</span><span class="ruby-operator">|</span>
182: 
183:             <span class="ruby-identifier">up</span> = <span class="ruby-identifier">uprow</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">ord</span>
184:             <span class="ruby-identifier">left</span> = <span class="ruby-identifier">line</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">-</span><span class="ruby-identifier">bpp</span>].<span class="ruby-identifier">ord</span>
185:             <span class="ruby-identifier">upleft</span> = <span class="ruby-identifier">uprow</span>[<span class="ruby-identifier">i</span><span class="ruby-operator">-</span><span class="ruby-identifier">bpp</span>].<span class="ruby-identifier">ord</span>
186: 
187:             <span class="ruby-keyword kw">case</span> <span class="ruby-identifier">predictor</span>
188:               <span class="ruby-keyword kw">when</span> <span class="ruby-constant">PNG_SUB</span>
189:                 <span class="ruby-identifier">line</span>[<span class="ruby-identifier">i</span>] = ((<span class="ruby-identifier">line</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">left</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0x</span><span class="ruby-constant">FF</span>).<span class="ruby-identifier">chr</span>
190:               <span class="ruby-keyword kw">when</span> <span class="ruby-constant">PNG_UP</span>
191:                 <span class="ruby-identifier">line</span>[<span class="ruby-identifier">i</span>] = ((<span class="ruby-identifier">line</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">up</span>) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0x</span><span class="ruby-constant">FF</span>).<span class="ruby-identifier">chr</span>
192:               <span class="ruby-keyword kw">when</span> <span class="ruby-constant">PNG_AVERAGE</span>
193:                 <span class="ruby-identifier">line</span>[<span class="ruby-identifier">i</span>] = ((<span class="ruby-identifier">line</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">-</span> ((<span class="ruby-identifier">left</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">up</span>) <span class="ruby-operator">/</span> <span class="ruby-value">2</span>)) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0x</span><span class="ruby-constant">FF</span>).<span class="ruby-identifier">chr</span>
194:               <span class="ruby-keyword kw">when</span> <span class="ruby-constant">PNG_PAETH</span>
195:                 <span class="ruby-identifier">p</span> = <span class="ruby-identifier">left</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">up</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">upleft</span>
196:                 <span class="ruby-identifier">pa</span>, <span class="ruby-identifier">pb</span>, <span class="ruby-identifier">pc</span> = (<span class="ruby-identifier">p</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">left</span>).<span class="ruby-identifier">abs</span>, (<span class="ruby-identifier">p</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">up</span>).<span class="ruby-identifier">abs</span>, (<span class="ruby-identifier">p</span> <span class="ruby-operator">-</span> <span class="ruby-identifier">upleft</span>).<span class="ruby-identifier">abs</span>
197: 
198:                 <span class="ruby-identifier">line</span>[<span class="ruby-identifier">i</span>] = ((<span class="ruby-identifier">line</span>[<span class="ruby-identifier">i</span>].<span class="ruby-identifier">ord</span> <span class="ruby-operator">-</span> 
199:                 <span class="ruby-keyword kw">case</span> [ <span class="ruby-identifier">pa</span>, <span class="ruby-identifier">pb</span>, <span class="ruby-identifier">pc</span> ].<span class="ruby-identifier">min</span>
200:                   <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">pa</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">left</span>
201:                   <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">pb</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">up</span>
202:                   <span class="ruby-keyword kw">when</span> <span class="ruby-identifier">pc</span> <span class="ruby-keyword kw">then</span> <span class="ruby-identifier">upleft</span>
203:                 <span class="ruby-keyword kw">end</span>
204:                 ) <span class="ruby-operator">&amp;</span> <span class="ruby-value">0x</span><span class="ruby-constant">FF</span>).<span class="ruby-identifier">chr</span>
205:               <span class="ruby-keyword kw">when</span> <span class="ruby-constant">PNG_NONE</span>
206:             <span class="ruby-keyword kw">else</span>
207:               <span class="ruby-identifier">raise</span> <span class="ruby-constant">PredictorError</span>, <span class="ruby-node">&quot;Unsupported PNG predictor : #{predictor}&quot;</span>
208:             <span class="ruby-keyword kw">end</span>
209:             
210:           <span class="ruby-keyword kw">end</span>
211:           
212:           <span class="ruby-identifier">line</span>[<span class="ruby-value">0</span>] = (<span class="ruby-identifier">predictor</span> <span class="ruby-operator">-</span> <span class="ruby-value">10</span>).<span class="ruby-identifier">chr</span>
213:           <span class="ruby-identifier">result</span> = <span class="ruby-identifier">line</span> <span class="ruby-operator">+</span> <span class="ruby-identifier">result</span>
214:           
215:           <span class="ruby-identifier">line</span> = <span class="ruby-identifier">uprow</span>
216:         <span class="ruby-keyword kw">end</span>
217:   
218:         <span class="ruby-identifier">result</span>
219:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000345" class="method-detail">
        <a name="M000345"></a>

        <div class="method-heading">
          <a href="#M000345" class="method-signature">
          <span class="method-name">do_post_prediction</span><span class="method-args">(data, predictor = NONE, colors = 1, bpc = 8, columns = 1)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000345-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000345-source">
<pre>
     <span class="ruby-comment cmt"># File origami/filters/predictors.rb, line 78</span>
 78:       <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">do_post_prediction</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">predictor</span> = <span class="ruby-constant">NONE</span>, <span class="ruby-identifier">colors</span> = <span class="ruby-value">1</span>, <span class="ruby-identifier">bpc</span> = <span class="ruby-value">8</span>, <span class="ruby-identifier">columns</span> = <span class="ruby-value">1</span>)
 79: 
 80:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">data</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">predictor</span> <span class="ruby-operator">==</span> <span class="ruby-constant">NONE</span>
 81: 
 82:         <span class="ruby-keyword kw">unless</span> (<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">4</span>) <span class="ruby-operator">===</span> <span class="ruby-identifier">colors</span>
 83:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">PredictorError</span>, <span class="ruby-value str">&quot;Colors must be between 1 and 4&quot;</span>
 84:         <span class="ruby-keyword kw">end</span>
 85: 
 86:         <span class="ruby-keyword kw">unless</span> [<span class="ruby-value">1</span>,<span class="ruby-value">2</span>,<span class="ruby-value">4</span>,<span class="ruby-value">8</span>,<span class="ruby-value">16</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">bpc</span>)
 87:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">PredictorError</span>, <span class="ruby-value str">&quot;BitsPerComponent must be in 1, 2, 4, 8 or 16&quot;</span>
 88:         <span class="ruby-keyword kw">end</span>
 89: 
 90:         <span class="ruby-comment cmt"># components per line</span>
 91:         <span class="ruby-identifier">nvals</span> = <span class="ruby-identifier">columns</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">colors</span>
 92: 
 93:         <span class="ruby-comment cmt"># bytes per pixel</span>
 94:         <span class="ruby-identifier">bpp</span> = (<span class="ruby-identifier">colors</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">bpc</span> <span class="ruby-operator">+</span> <span class="ruby-value">7</span>) <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">3</span>
 95: 
 96:         <span class="ruby-comment cmt"># bytes per row</span>
 97:         <span class="ruby-identifier">bpr</span> = ((<span class="ruby-identifier">nvals</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">bpc</span> <span class="ruby-operator">+</span> <span class="ruby-value">7</span>) <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">3</span>) <span class="ruby-operator">+</span> <span class="ruby-value">1</span>
 98: 
 99:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">predictor</span> <span class="ruby-operator">==</span> <span class="ruby-constant">TIFF</span>
100:           <span class="ruby-identifier">do_tiff_post_prediction</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">colors</span>, <span class="ruby-identifier">bpc</span>, <span class="ruby-identifier">columns</span>)
101:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">predictor</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-value">10</span> <span class="ruby-comment cmt"># PNG</span>
102:           <span class="ruby-identifier">do_png_post_prediction</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">bpp</span>, <span class="ruby-identifier">bpr</span>)
103:         <span class="ruby-keyword kw">else</span>
104:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">PredictorError</span>, <span class="ruby-node">&quot;Unknown predictor : #{predictor}&quot;</span>
105:         <span class="ruby-keyword kw">end</span>
106:       <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>

      <div id="method-M000344" class="method-detail">
        <a name="M000344"></a>

        <div class="method-heading">
          <a href="#M000344" class="method-signature">
          <span class="method-name">do_pre_prediction</span><span class="method-args">(data, predictor = NONE, colors = 1, bpc = 8, columns = 1)</span>
          </a>
        </div>
      
        <div class="method-description">
          <p><a class="source-toggle" href="#"
            onclick="toggleCode('M000344-source');return false;">[Source]</a></p>
          <div class="method-source-code" id="M000344-source">
<pre>
    <span class="ruby-comment cmt"># File origami/filters/predictors.rb, line 44</span>
44:       <span class="ruby-keyword kw">def</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">do_pre_prediction</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">predictor</span> = <span class="ruby-constant">NONE</span>, <span class="ruby-identifier">colors</span> = <span class="ruby-value">1</span>, <span class="ruby-identifier">bpc</span> = <span class="ruby-value">8</span>, <span class="ruby-identifier">columns</span> = <span class="ruby-value">1</span>)
45:       
46:         <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">data</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">predictor</span> <span class="ruby-operator">==</span> <span class="ruby-constant">NONE</span>
47: 
48:         <span class="ruby-keyword kw">unless</span> (<span class="ruby-value">1</span><span class="ruby-operator">..</span><span class="ruby-value">4</span>) <span class="ruby-operator">===</span> <span class="ruby-identifier">colors</span>.<span class="ruby-identifier">to_i</span>
49:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">PredictorError</span>, <span class="ruby-value str">&quot;Colors must be between 1 and 4&quot;</span>
50:         <span class="ruby-keyword kw">end</span>
51: 
52:         <span class="ruby-keyword kw">unless</span> [<span class="ruby-value">1</span>,<span class="ruby-value">2</span>,<span class="ruby-value">4</span>,<span class="ruby-value">8</span>,<span class="ruby-value">16</span>].<span class="ruby-identifier">include?</span>(<span class="ruby-identifier">bpc</span>.<span class="ruby-identifier">to_i</span>)
53:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">PredictorError</span>, <span class="ruby-value str">&quot;BitsPerComponent must be in 1, 2, 4, 8 or 16&quot;</span>
54:         <span class="ruby-keyword kw">end</span>
55: 
56:         <span class="ruby-comment cmt"># components per line</span>
57:         <span class="ruby-identifier">nvals</span> = <span class="ruby-identifier">columns</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">colors</span>
58: 
59:         <span class="ruby-comment cmt"># bytes per pixel</span>
60:         <span class="ruby-identifier">bpp</span> = (<span class="ruby-identifier">colors</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">bpc</span> <span class="ruby-operator">+</span> <span class="ruby-value">7</span>) <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">3</span>
61: 
62:         <span class="ruby-comment cmt"># bytes per row</span>
63:         <span class="ruby-identifier">bpr</span> = (<span class="ruby-identifier">nvals</span> <span class="ruby-operator">*</span> <span class="ruby-identifier">bpc</span> <span class="ruby-operator">+</span> <span class="ruby-value">7</span>) <span class="ruby-operator">&gt;&gt;</span> <span class="ruby-value">3</span>
64: 
65:         <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">data</span>.<span class="ruby-identifier">size</span> <span class="ruby-operator">%</span> <span class="ruby-identifier">bpr</span> <span class="ruby-operator">==</span> <span class="ruby-value">0</span>
66:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">PredictorError</span>, <span class="ruby-node">&quot;Invalid data size #{data.size}, should be multiple of bpr=#{bpr}&quot;</span>
67:         <span class="ruby-keyword kw">end</span>
68: 
69:         <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">predictor</span> <span class="ruby-operator">==</span> <span class="ruby-constant">TIFF</span>
70:           <span class="ruby-identifier">do_tiff_pre_prediction</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">colors</span>, <span class="ruby-identifier">bpc</span>, <span class="ruby-identifier">columns</span>)
71:         <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">predictor</span> <span class="ruby-operator">&gt;=</span> <span class="ruby-value">10</span> <span class="ruby-comment cmt"># PNG</span>
72:           <span class="ruby-identifier">do_png_pre_prediction</span>(<span class="ruby-identifier">data</span>, <span class="ruby-identifier">predictor</span>, <span class="ruby-identifier">bpp</span>, <span class="ruby-identifier">bpr</span>)
73:         <span class="ruby-keyword kw">else</span>
74:           <span class="ruby-identifier">raise</span> <span class="ruby-constant">PredictorError</span>, <span class="ruby-node">&quot;Unknown predictor : #{predictor}&quot;</span>
75:         <span class="ruby-keyword kw">end</span>
76:      <span class="ruby-keyword kw">end</span>
</pre>
          </div>
        </div>
      </div>


    </div>


  </div>


<div id="validator-badges">
  <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
</div>

</body>
</html>